﻿package 
{
    import ActivityDownTimer.*;
    import com.assist.*;
    import com.assist.view.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class ActivityDownTimer extends ActivityDownTimerBase
    {
        private var _isShowBtn:Boolean = false;
        private var _diffTime:int = 0;
        private var _timerStr:String = "";
        private var _endTime:int = 0;
        private var _newTime:int = 0;
        private var _onDownTimeEnd:Function;
        private var _onMinute:Function;
        private var _mcType:String = "";
        public var EndTimerStr:String = "";
        private var _startTimerColor:uint = 16777215;
        private var _endTimerColor:uint = 16777215;
        private var _onClick:Function;
        private var _timer:Timer;
        private var _downTimer:Number = 0;
        private var _isDownTimer:Boolean = false;
        private var _changeColor:int = 0;
        private var _f:int = 0;
        private var _s:int = 0;
        private var _fStr:String = "";
        private var _sStr:String = "";

        public function ActivityDownTimer()
        {
            this._onDownTimeEnd = new Function();
            this._onMinute = new Function();
            this._onClick = new Function();
            this._timer = new Timer(1000);
            this._timer.addEventListener(TimerEvent.TIMER, this.onDownTimer);
            _Btn.addEventListener(MouseEvent.CLICK, this.onBtnClick);
            return;
        }// end function

        public function set isShowBtn(param1:Boolean) : void
        {
            this.visible = param1;
            this._isShowBtn = param1;
            return;
        }// end function

        public function set diffTime(param1:int) : void
        {
            this._diffTime = param1;
            return;
        }// end function

        public function set downTimer(param1:int) : void
        {
            var _loc_2:* = param1;
            this._newTime = new Date().getTime() / 1000 - this._diffTime;
            this._endTime = this._newTime + _loc_2;
            this._downTimer = Math.floor(this._endTime - this._newTime);
            this.downTimerInfo();
            if (this._isDownTimer == false)
            {
                this._isDownTimer = true;
                this._timer.start();
            }
            return;
        }// end function

        public function set onDownTimeEnd(param1:Function) : void
        {
            this._onDownTimeEnd = param1;
            return;
        }// end function

        public function set onMinute(param1:Function) : void
        {
            this._onMinute = param1;
            return;
        }// end function

        private function downTimerInfo() : void
        {
            var _loc_1:Boolean = false;
            this.visible = this._isShowBtn;
            _Btn.visible = this._isShowBtn;
            if (this._downTimer <= 0)
            {
                this._onDownTimeEnd(this._mcType);
                this._downTimer = -1;
                if (this._changeColor == 0)
                {
                    this.htmlText(this.EndTimerStr, 12, this._startTimerColor);
                    this._changeColor = 1;
                }
                else
                {
                    this.htmlText(this.EndTimerStr, 12, this._endTimerColor);
                    this._changeColor = 0;
                }
            }
            else
            {
                _loc_1 = this._downTimer > 3600;
                this._timerStr = TimeChange.mainTime(this._downTimer, ":", _loc_1);
                this.htmlText(this._timerStr, 12, this._startTimerColor);
            }
            return;
        }// end function

        public function set activityBtn(param1:SimpleButton) : void
        {
            this.x = param1.x + 9;
            this.y = param1.y + 68;
            return;
        }// end function

        public function set mcType(param1:String) : void
        {
            this._mcType = param1;
            return;
        }// end function

        public function set endTimerStr(param1:String) : void
        {
            this.EndTimerStr = param1;
            return;
        }// end function

        public function set startTimerColor(param1:uint) : void
        {
            this._startTimerColor = param1;
            return;
        }// end function

        public function set endTimerColor(param1:uint) : void
        {
            this._endTimerColor = param1;
            return;
        }// end function

        public function set onClick(param1:Function) : void
        {
            this._onClick = param1;
            return;
        }// end function

        private function onBtnClick(event:MouseEvent) : void
        {
            this._onClick(this._mcType);
            return;
        }// end function

        private function onDownTimer(event:TimerEvent) : void
        {
            this._newTime = new Date().getTime() / 1000 - this._diffTime;
            this._downTimer = Math.floor(this._endTime - this._newTime);
            if (this._downTimer >= 0)
            {
            }
            if (this._downTimer % 60 == 0)
            {
                this._onMinute(this._mcType, this._downTimer);
            }
            this.downTimerInfo();
            return;
        }// end function

        private function htmlText(param1:String, param2:int, param3:uint, param4:Boolean = false, param5:Boolean = false) : void
        {
            _DownTimer.htmlText = htmlFormat(param1, param2, param3, param4, param5);
            return;
        }// end function

        public function clear() : void
        {
            this._isDownTimer = false;
            this._timer.stop();
            this._timer.removeEventListener(TimerEvent.TIMER, this.onDownTimer);
            _Btn.removeEventListener(MouseEvent.CLICK, this.onBtnClick);
            return;
        }// end function

        private function renderTime(param1:int) : String
        {
            var _loc_2:* = param1;
            if (_loc_2 / 60 > 0)
            {
                this._f = Math.floor(_loc_2 / 60);
                _loc_2 = _loc_2 - this._f * 60;
            }
            this._s = _loc_2;
            this._fStr = this._f + "";
            this._sStr = this._s + "";
            if (this._f < 10)
            {
                this._fStr = "0" + this._f;
            }
            if (this._s < 10)
            {
                this._sStr = "0" + this._s;
            }
            var _loc_3:* = this._fStr + ":" + this._sStr;
            return _loc_3;
        }// end function

    }
}
